package ${location}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import ${location}.common.ResponseResult;
import ${location}.model.dto.${camelClassName}.${className}AddDto;
import ${location}.model.dto.${camelClassName}.${className}PageDto;
import ${location}.model.vo.${camelClassName}.${className}Vo;
import ${location}.service.${className}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author ${author}
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/${restMappingClassName}s")
@Api(tags = "${tableName}<#if tableComment!=tableName> ${tableComment}<#else >表Controller</#if>")
public class ${className}Controller {

	private final ${className}Service ${camelClassName}Service;

	@PostMapping
	@ApiOperation(value = "新增数据")
	public ResponseResult<${className}Vo> saveEntity(@RequestBody ${className}AddDto ${camelClassName}) {
		return ResponseResult.success(${camelClassName}Service.saveEntity(${camelClassName}));
	}

	@DeleteMapping("/{id}")
	@ApiOperation(value = "通过主键删除数据")
	public ResponseResult<${idType}> deleteEntityById(@PathVariable("id") ${idType} id) {
		return ResponseResult.success(${camelClassName}Service.deleteEntityById(id));
	}

	@PutMapping("/{id}")
	@ApiOperation(value = "更新数据")
	public ResponseResult<${className}Vo> updateEntityById(@PathVariable("id") ${idType} id, @RequestBody ${className}AddDto ${camelClassName}) {
		return ResponseResult.success(${camelClassName}Service.updateEntityById(id, ${camelClassName}));
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "通过id查询单条数据")
	public ResponseResult<${className}Vo> getEntityById(@PathVariable("id") ${idType} id) {
		return ResponseResult.success(${camelClassName}Service.getEntityById(id));
	}

	@PostMapping("/page")
	@ApiOperation(value = "分页查询")
	public ResponseResult<IPage<${className}Vo>> pageQuery(@RequestBody ${className}PageDto ${camelClassName}ListDto) {
		return ResponseResult.success(${camelClassName}Service.pageQuery(${camelClassName}ListDto));
	}
}
